; ########################################################################
;
; strip.mrc 
; Author: blue-elf
; Email: belf@usa.net
; 29 May 1999
;
; ----- What this addon does ---------------------------------------------
;
; This is a scripter's addon. If you use format/theme system, this will
; allow you to display the text stripped of the control codes depending
; on your default mIRC settings. In other words, it reads mirc.ini for
; your control code stripping. If color stripping is on, only color codes
; will be stripped, if underline stripping is on, only underline codes
; are stripped.. and so on. Go down to the bottom of this file for
; a sample usage.
;
; ----- About this addon -------------------------------------------------
;
; These aliases are originally from mIRCii v12.26. Apparently, not many
; scripters are willing to wade through the mIRCii code, heh... So here
; it is, now for public usage.
;
; ---- Copyrights, trademark, etc ----------------------------------------
;
; This is not copyrighted .. and it'd be a bit stupid to copyright it.
; So like you can use it in your script any way you want. BUT DO NOT
; CLAIM IT TO BE YOUR ORIGINAL CODE. Recently, my script Basic was ripped
; by some idiot and he even tried to defend himself. Too bad he can't
; disprove the fact that he did rip my script. So don't even think about
; it. If you wanna use this, make sure you mention where you got this
; from. There's a thing called "courtesy" and I myself would mention your
; nick if I used an identifier or two from you.
;
; One other thing.. you can rename the identifiers but still, tell everyone
; who the original author is..
;
; - peace -
;
; ###########################################################################
;
; begin code .. heh
;
alias cstrip {
  if ( !isin $1-) return $1-
  %elf.-v =
  %elf.-x = $numtok($1-,32)
  :x
  %elf.-v = $iif( isin $gettok($1-,%elf.-x,32),$cstrip2($gettok($1-,%elf.-x,32)),$gettok($1-,%elf.-x,32)) %elf.-v
  dec -u %elf.-x
  if (%elf.-x) goto x
  return %elf.-v
}
alias cstrip2 {
  if ($1 == ) return  
  if (((? iswm $1) && ($mid($1,2,1) isnum)) || ((?? iswm $1) && ($mid($1,2,2) isnum))) return  
  if (((?,? iswm $1) || (??,?? iswm $1) || (??,? iswm $1) || (?,?? iswm $1)) && (($remove($gettok($1,1,44),) isnum) && ($gettok($1,2,44) isnum))) return  
  %elf.strpt = $1
  :s
  %elf.strpd =
  %elf.st =
  :c
  inc %elf.st
  if ($mid(%elf.strpt,%elf.st,1) != $null) {
    if ($ifmatch == ) {
      if ($mid(%elf.strpt,$calc(%elf.st + 1),1) isnum) {
        if ($mid(%elf.strpt,$calc(%elf.st + 1),2) isnum) inc -u %elf.st 3 | else inc -u %elf.st 2
        if ($mid(%elf.strpt,%elf.st,1) == ,) { if ($mid(%elf.strpt,$calc(%elf.st + 1),2) isnum) inc -u %elf.st 3 | elseif ($mid(%elf.strpt,$calc(%elf.st + 1),1) isnum) inc -u %elf.st 2 }
      }
      else inc -u %elf.st 1
    }
    %elf.strpd = %elf.strpd $+ $mid(%elf.strpt,%elf.st,1) | goto c
  }
  if ( isin %elf.strpd) { %elf.strpt = %elf.strpd | goto s }
  return $iif(%elf.strpd,%elf.strpd, )
}
alias repb {
  if ( !isin $1-) return $1-
  if ($1- == ) return  
  unset %elf.rep.r %elf.rep.p
  %elf.rep.t = $numtok($1-,32)
  :r
  inc %elf.rep.r
  if (%elf.rep.r <= %elf.rep.t) {
    if ( !isin $gettok($1-,%elf.rep.r,32)) { %elf.rep.p = %elf.rep.p $gettok($1-,%elf.rep.r,32) | goto r }
    %elf.rep.d = $gettok($1-,%elf.rep.r,32)
    unset %elf.rep.b %elf.rep.s
    :loop
    inc %elf.rep.s
    if ($mid(%elf.rep.d,%elf.rep.s,1) != $null) {
      if ($ifmatch == ) {
        if ($mid(%elf.rep.d,$calc(%elf.rep.s + 2),1) == ,) && ($_bk($mid(%elf.rep.d,%elf.rep.s,2))) { %elf.rep.b = %elf.rep.b $+ 15 | inc -u %elf.rep.s 2 }
        elseif ($mid(%elf.rep.d,$calc(%elf.rep.s + 3),1) == ,) && ($_bk($mid(%elf.rep.d,%elf.rep.s,3))) { %elf.rep.b = %elf.rep.b $+ 15 | inc -u %elf.rep.s 3 }
        elseif (($_bk($mid(%elf.rep.d,%elf.rep.s,2))) && ($mid(%elf.rep.d,$calc(%elf.rep.s + 2),1) !isnum)) inc -u %elf.rep.s 2
        elseif ($_bk($mid(%elf.rep.d,%elf.rep.s,3))) inc -u %elf.rep.s 3
      }
      %elf.rep.b = %elf.rep.b $+ $mid(%elf.rep.d,%elf.rep.s,1)
      goto loop
    }
    %elf.rep.p = %elf.rep.p %elf.rep.b
    goto r
  }
  return %elf.rep.p
}
alias _a set -u %elf.ini $readini -n $mircini options n6 | return $gettok(%elf.ini,19,44)
alias _bk if ($colour(back)) return $istok(01 1 17 33 49 65 81 97,$1,32) | return $istok(96 80 64 48 32 16 0,$1,32)
alias _strip {
  if ($left($1,1) == $null) { echo $colour(info) -ts * Invalid format: $!_strip | return }
  set -u %elf. $1-
  if ($_a) set -u %elf. $ansi2mirc(%elf.)
  set -u %elf. $readini -n $mircini options n5
  goto $gettok(%elf.,25,44)
  :0 | return $repb(%elf.)
  :1 | return $repb($remove(%elf.,))
  :2 | return $repb($remove(%elf.,))
  :3 | return $repb($remove(%elf.,,))
  :4 | return $repb($remove(%elf.,))
  :5 | return $repb($remove(%elf.,,))
  :6 | return $repb($remove(%elf.,,))
  :7 | return $repb($remove(%elf.,,,))
  :8 | return $cstrip(%elf.)
  :9 | return $cstrip($remove(%elf.,))
  :10 | return $cstrip($remove(%elf.,))
  :11 | return $cstrip($remove(%elf.,,))
  :12 | return $cstrip($remove(%elf.,))
  :13 | return $cstrip($remove(%elf.,,))
  :14 | return $cstrip($remove(%elf.,,))
  :15 | return $strip(%elf.)
}

; ############################################################
;
; Sample event
;
; --- Short explanation -------------------------------------
; 
; I'm using debug.log because mIRC strips the extra
; spaces in $1- but with this way, when you set a
; variable from a $read, the spaces are preserved so
; we replace the spaces from there - thanks to pai.  
;
; If you use debug.log, you might want to /write -c debug.log
; everytime you read from it to speed things up.
;
; ############################################################

on *:connect:debug on
on ^*:action:*:#:{
  haltdef
  set %elf.debug $read -nl [ $+ [ $lines(debug.log) ] ] debug.log
  set %elf.debug $replace(%elf.debug,$chr(32), ) 
  set %elf.debug $remove($mid(%elf.debug,$add($pos(%elf.debug,:,2),1),$len(%elf.debug)),ACTION,)
  ; Modify the line below for your format/theme system
  ; Take note that there is an extra space just before the text because we have replaced
  ; all spaces with ^b^b ^b^b
  echo #  $+ $colour(action) $+ ! $nick $+  $+ $colour(action) $+ $_strip(%elf.debug)
}
; EOF

